﻿package mortal.game.view.guild.cellrender
{
    import Message.Client.*;
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.daily.*;

    public class GuildBustlingRenderer extends GCellRenderer
    {
        private var _icon:GImageBitmap;
        private var _name:GTextFiled;
        private var _enjoyLv:GTextFiled;
        private var _time:GTextFiled;
        private var _starPanel:StarPanel;
        private var _btnFlyBoot:GLoadedButton;
        private var _operBtn:GButton;
        private var _num:BitmapNumberText;
        private var _rewardIcon:GBitmap;
        private var _state:GBitmap;

        public function GuildBustlingRenderer()
        {
            return;
        }// end function

        private function get itemData() : TDailyViewConfig
        {
            return data as TDailyViewConfig;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._icon.imgUrl = this.itemData.icon + ".jpg";
            this._btnFlyBoot.visible = false;
            this._name.text = this.itemData.name;
            this._num.text = "+" + this.itemData.guildActivity;
            this._enjoyLv.htmlText = Language.getStringByParam(70484, this.itemData.minLevel);
            this.setBtnLabel();
            this.setPlanTxt();
            this.setStar();
            return;
        }// end function

        private function onClickOperBtn(event:MouseEvent) : void
        {
            DailyUtil.oper(this.itemData);
            return;
        }// end function

        private function setPlanTxt() : void
        {
            var _loc_2:String = null;
            var _loc_3:String = null;
            var _loc_4:Array = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_1:* = Cache.instance.daily;
            this._time.textColor = GlobalStyle.colorLvUint;
            if (int(this.itemData.times) > 0)
            {
                if (int(_loc_1.data.times[this.itemData.type]) >= int(this.itemData.activityValue))
                {
                    this._time.textColor = GlobalStyle.colorHuang2Uint;
                    this._time.text = int(this.itemData.activityValue) + "/" + this.itemData.activityValue;
                }
                else
                {
                    this._time.text = int(_loc_1.data.times[this.itemData.type]) + "/" + this.itemData.activityValue;
                }
            }
            else if (this.itemData.normalOpenDt)
            {
                _loc_2 = DailyUtil.getTimeStr(this.itemData.normalOpenDt);
                if (this.itemData.openWeekDay)
                {
                    _loc_3 = "";
                    _loc_4 = this.itemData.openWeekDay.split("#");
                    _loc_5 = _loc_4.length;
                    _loc_6 = 0;
                    while (_loc_6 < _loc_5)
                    {
                        
                        _loc_3 = _loc_3 + GameDefConfig.instance.getChineseNum(int(_loc_4[_loc_6]));
                        _loc_6++;
                    }
                    this._time.text = Language.getStringByParam(70407, _loc_3 + _loc_2);
                }
                else
                {
                    this._time.text = Language.getStringByParam(70408, _loc_2);
                }
            }
            else
            {
                this._time.text = "" + Language.getString(71088);
            }
            this._state.visible = DailyUtil.isComplete(this.itemData);
            return;
        }// end function

        private function setStar() : void
        {
            if (this.itemData.expStar > 0)
            {
                this._rewardIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildBustlingTxt4);
                this._starPanel.setStarNum(this.itemData.expStar, this.itemData.expStar);
            }
            else if (this.itemData.coinStar > 0)
            {
                this._rewardIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildBustlingTxt5);
                this._starPanel.setStarNum(this.itemData.coinStar, this.itemData.coinStar);
            }
            else if (this.itemData.itemStar > 0)
            {
                this._rewardIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildBustlingTxt1);
                this._starPanel.setStarNum(this.itemData.itemStar, this.itemData.itemStar);
            }
            return;
        }// end function

        private function setBtnLabel() : void
        {
            if (this.itemData.operType == EDailyOperType._EDailyOperTypeModule)
            {
                this._operBtn.label = Language.getString(70404);
            }
            else if (this.itemData.operType == EDailyOperType._EDailyOperTypePathing)
            {
                this._btnFlyBoot.visible = true;
                this._operBtn.label = Language.getString(70403);
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.GuildBustlingBg1, 0, 0, this));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.TitleLine, 35, 12, this));
            var _loc_1:* = UIFactory.gBitmap(ImagesConst.TitleLine, 320, 12, this);
            _loc_1.scaleX = -1;
            pushUIToDisposeVec(_loc_1);
            this._icon = UIFactory.gImageBitmap("", 7, 34, this);
            this._state = UIFactory.gBitmap(ImagesConst.GuildBustlingTxt6, 270, 5, this);
            this._name = UIFactory.gTextField(Language.getString(70483), 110, 2, 105, 40, this, GlobalStyle.textFormatBai.setSize(14).center());
            this._rewardIcon = UIFactory.gBitmap(ImagesConst.GuildBustlingTxt1, 75, 70, this);
            this._enjoyLv = UIFactory.gTextField(Language.getStringByParam(70484, 2), 75, 38, 120, 20, this, GlobalStyle.textFormatHuang, true);
            this._time = UIFactory.gTextField("" + Language.getString(71089), 180, 38, 150, 20, this, GlobalStyle.textFormatLv.right());
            this._starPanel = UIFactory.getUICompoment(StarPanel, 105, 65, this);
            this._starPanel.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            this._btnFlyBoot = UIFactory.gLoadedButton(ImagesConst.MapBtnFlyBoot_upSkin, 255, 71, 16, 18, this);
            this._operBtn = UIFactory.gButton("", 272, 68, 62, 22, this);
            this._num = UIFactory.bitmapNumberText(203, 5, "GuildBustlingNum.png", 14, 22, 0, this, 15);
            this._operBtn.configEventListener(MouseEvent.CLICK, this.onClickOperBtn);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._icon.dispose(param1);
            this._name.dispose(param1);
            this._enjoyLv.dispose(param1);
            this._time.dispose(param1);
            this._starPanel.dispose(param1);
            this._btnFlyBoot.dispose(param1);
            this._operBtn.dispose(param1);
            this._num.dispose(param1);
            this._state.dispose(param1);
            this._rewardIcon.dispose(param1);
            this._icon = null;
            this._name = null;
            this._enjoyLv = null;
            this._time = null;
            this._starPanel = null;
            this._btnFlyBoot = null;
            this._operBtn = null;
            this._num = null;
            this._state = null;
            this._rewardIcon = null;
            return;
        }// end function

    }
}
